// Chart configurations and data
document.addEventListener('DOMContentLoaded', function() {
    // Wealth vs Satisfaction Line Graph
    const wealthSatisfactionCtx = document.getElementById('wealthSatisfactionGraph').getContext('2d');
    new Chart(wealthSatisfactionCtx, {
        type: 'line',
        data: {
            labels: ['Early Period', 'Early-Mid', 'Mid Period', 'Mid-Late', 'Late Period'],
            datasets: [{
                label: 'Wealth Consumption',
                data: [100, 95, 85, 70, 55],
                borderColor: '#36A2EB',
                backgroundColor: 'rgba(54, 162, 235, 0.1)',
                tension: 0.4
            }, {
                label: 'Satisfaction Level',
                data: [90, 85, 60, 40, 25],
                borderColor: '#FF6384',
                backgroundColor: 'rgba(255, 99, 132, 0.1)',
                tension: 0.4
            }]
        },
        options: {
            responsive: true,
            plugins: {
                title: {
                    display: true,
                    text: 'Wealth Consumption vs. Satisfaction Over Time'
                },
                tooltip: {
                    mode: 'index',
                    intersect: false
                }
            },
            scales: {
                y: {
                    beginAtZero: true,
                    max: 100,
                    title: {
                        display: true,
                        text: 'Level (0-100)'
                    }
                }
            }
        }
    });

    // Resource Distribution Pie Chart
    const resourcePieCtx = document.getElementById('resourcePieChart').getContext('2d');
    new Chart(resourcePieCtx, {
        type: 'pie',
        data: {
            labels: [
                'Household Staff & Maintenance (30%)',
                'Social Events & Entertainment (25%)',
                'Luxury Goods & Personal Items (20%)',
                'Garden & Estate Upkeep (15%)',
                'Gifts & Social Obligations (10%)'
            ],
            datasets: [{
                data: [30, 25, 20, 15, 10],
                backgroundColor: [
                    '#FF6384',
                    '#36A2EB',
                    '#FFCE56',
                    '#4BC0C0',
                    '#9966FF'
                ]
            }]
        },
        options: {
            responsive: true,
            plugins: {
                title: {
                    display: true,
                    text: 'Distribution of Family Resources'
                },
                legend: {
                    position: 'bottom'
                }
            }
        }
    });

    // Initial vs Final Utility Bar Graph
    const utilityBarCtx = document.getElementById('utilityBarGraph').getContext('2d');
    new Chart(utilityBarCtx, {
        type: 'bar',
        data: {
            labels: [
                'Grand View Garden',
                'Household Staff',
                'Social Events',
                'Luxury Goods',
                'Estate Maintenance',
                'Cultural Activities'
            ],
            datasets: [{
                label: 'Initial Utility Value',
                data: [95, 90, 85, 88, 82, 80],
                backgroundColor: '#36A2EB'
            }, {
                label: 'Final Utility Value',
                data: [30, 35, 25, 20, 15, 10],
                backgroundColor: '#FF6384'
            }]
        },
        options: {
            responsive: true,
            plugins: {
                title: {
                    display: true,
                    text: 'Initial vs Final Utility Values'
                },
                legend: {
                    position: 'bottom'
                }
            },
            scales: {
                y: {
                    beginAtZero: true,
                    max: 100,
                    title: {
                        display: true,
                        text: 'Utility Value (0-100)'
                    }
                }
            }
        }
    });
});

// Handle responsive chart resizing
window.addEventListener('resize', function() {
    Chart.instances.forEach(chart => {
        chart.resize();
    });
});